/**
 * Created by forcht on 2018/5/17.
 */
public class Solution {
    public String longestPalindrome(String s) {
        boolean[][] p=new boolean[s.length()][s.length()];
        int left=0,right=0;
        for(int i=0;i<s.length();i++){
            for(int j=0;j<=i;j++){
                if(s.charAt(i)==s.charAt(j)&&(i-j<2||p[j+1][i-1])){
                    p[j][i]=true;
                    if((right-left)<(i-j)){
                        left=j;
                        right=i;
                    }
                }
            }
        }
        return s.substring(left,right+1);
    }

    public static void main(String[] args) {
       Solution solution=new Solution();
        System.out.println(solution.longestPalindrome("bb"));
    }
}
